package cn.itsource.user.service.impl;

import cn.itsource.basic.exception.CustomException;
import cn.itsource.basic.service.impl.BaseServiceImpl;
import cn.itsource.user.domain.User;
import cn.itsource.user.mapper.UserMapper;
import cn.itsource.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public void checkPhone(String phone) throws CustomException {
        //手机号码为空，就抛出异常
        if(StringUtils.isEmpty(phone)){
            throw new CustomException("手机号码不能为空!!");
        }

        //根据手机号码查询用户对象
        User user = userMapper.loadByPhone(phone);
        if (user != null) {
            throw new CustomException("手机号码已被注册!!");
        }

    }

    @Override
    public User loadByLogininfoid(Long logininfoid) {
        return userMapper.loadByLogininfoid(logininfoid);
    }

}
